class Solution {
public:
    int findJudge(int n, vector<vector<int>>& trust) {
        int i;
        vector<int> I(n+1, 0);
        vector<int> O(n+1, 0);
        for (auto & d: trust) {
            I[d[1]]++;
            O[d[0]]++;
        }
        for (i = 1; i <= n; ++i) {
            if (I[i] == n-1 and O[i] == 0) {
                return i;
            }
        }
        return -1;
    }
};